package JiHeDemo;

import java.util.Objects;

public class Student implements Comparable<Student> {
	private String name;
	private int age;

	public Student(String name, int age) {
		this.name = name;
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Student{" +
				"name='" + name + '\'' +
				", age=" + age +
				'}';
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof Student)) return false;
		Student student = (Student) o;
		return getAge() == student.getAge() && getName().equals(student.getName());
	}

	@Override
	public int hashCode() {
		return Objects.hash(getName(), getAge());
	}

	@Override
	public int compareTo(Student o) {
		int n1 = this.getName().compareTo(o.getName());
		int n2 = this.age - o.getAge();

		return n1 == 0 ? n2 : n1;
	}
}